Skip to content

Fix libp2p and WebSocket IPv6 test timeouts with Node 24 and libsodium 0.8.0#1002

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-libsodium-initialization
Draft

Fix libp2p and WebSocket IPv6 test timeouts with Node 24 and libsodium 0.8.0#1002
Copilot wants to merge 2 commits intomainfrom
copilot/fix-libsodium-initialization

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 10, 2026

After upgrading to Node 24 and libsodium 0.8.0, two IPv6 networking tests fail intermittently due to race conditions in libsodium initialization and tight WebSocket handshake timeouts.

Changes

  • libp2pTransport.ts: Await sodium.ready before starting libp2p to prevent crypto handshakes racing with libsodium initialization

    async start(): Promise<void> {
      try {
        await sodium.ready;
      } catch (error) {
        logger.warn(`libp2pTransport: Failed to initialize libsodium: ${error}, continuing anyway`);
      }
      // ... existing libp2p setup
    }
  • webSocketConnection.ts: Increase WEBSOCKET_HANDSHAKE_TIMEOUT from 2500ms to 10000ms to tolerate slower IPv6 and crypto initialization handshakes

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • bt1.archive.org
    • Triggering command: /opt/hostedtoolcache/node/24.12.0/x64/bin/node /opt/hostedtoolcache/node/24.12.0/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/verity/verity/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/verity/verity/node_modules/vitest/dist/workers/forks.js (dns block)
  • bt2.archive.org
    • Triggering command: /opt/hostedtoolcache/node/24.12.0/x64/bin/node /opt/hostedtoolcache/node/24.12.0/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/verity/verity/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/verity/verity/node_modules/vitest/dist/workers/forks.js (dns block)
  • global.stun.twilio.com
    • Triggering command: /opt/hostedtoolcache/node/24.12.0/x64/bin/node /opt/hostedtoolcache/node/24.12.0/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/verity/verity/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/verity/verity/node_modules/vitest/dist/workers/forks.js (dns block)
  • opentracker.i2p.rocks
    • Triggering command: /opt/hostedtoolcache/node/24.12.0/x64/bin/node /opt/hostedtoolcache/node/24.12.0/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/verity/verity/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/verity/verity/node_modules/vitest/dist/workers/forks.js (dns block)
  • retracker.lanta-net.ru
    • Triggering command: /opt/hostedtoolcache/node/24.12.0/x64/bin/node /opt/hostedtoolcache/node/24.12.0/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/verity/verity/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/verity/verity/node_modules/vitest/dist/workers/forks.js (dns block)
  • stun.l.google.com
    • Triggering command: /opt/hostedtoolcache/node/24.12.0/x64/bin/node /opt/hostedtoolcache/node/24.12.0/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/verity/verity/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/verity/verity/node_modules/vitest/dist/workers/forks.js (dns block)
  • tracker.files.fm
    • Triggering command: /opt/hostedtoolcache/node/24.12.0/x64/bin/node /opt/hostedtoolcache/node/24.12.0/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/verity/verity/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/verity/verity/node_modules/vitest/dist/workers/forks.js (dns block)
  • tracker.gbitt.info
    • Triggering command: /opt/hostedtoolcache/node/24.12.0/x64/bin/node /opt/hostedtoolcache/node/24.12.0/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/verity/verity/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/verity/verity/node_modules/vitest/dist/workers/forks.js (dns block)
  • tracker.openbittorrent.com
    • Triggering command: /opt/hostedtoolcache/node/24.12.0/x64/bin/node /opt/hostedtoolcache/node/24.12.0/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/verity/verity/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/verity/verity/node_modules/vitest/dist/workers/forks.js (dns block)
  • tracker.opentrackr.org
    • Triggering command: /opt/hostedtoolcache/node/24.12.0/x64/bin/node /opt/hostedtoolcache/node/24.12.0/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/verity/verity/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/verity/verity/node_modules/vitest/dist/workers/forks.js (dns block)
  • tracker.tamersunion.org
    • Triggering command: /opt/hostedtoolcache/node/24.12.0/x64/bin/node /opt/hostedtoolcache/node/24.12.0/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/verity/verity/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/verity/verity/node_modules/vitest/dist/workers/forks.js (dns block)
  • tracker.torrent.eu.org
    • Triggering command: /opt/hostedtoolcache/node/24.12.0/x64/bin/node /opt/hostedtoolcache/node/24.12.0/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/verity/verity/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/verity/verity/node_modules/vitest/dist/workers/forks.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Tests started failing after upgrading to Node 24 and libsodium 0.8.0. Two end-to-end networking tests fail intermittently: the libp2p IPv6 test times out and the WebSocket IPv6 test shows an assertion that a peer never became online. Root cause analysis shows startup/handshake timing and crypto initialization (libsodium) can delay libp2p and WebSocket handshakes, which causes the tests to time out or assert false.

Change summary (what to implement in this PR):

  1. Ensure libsodium is initialized before starting libp2p.

    • File: src/core/networking/transport/libp2p/libp2pTransport.ts
    • Add an import for libsodium-wrappers-sumo (sodium) and await sodium.ready at the start of the async start() method before constructing/creating the libp2p node. This prevents starting libp2p while libsodium is still initializing which can slow or break crypto handshakes.
    • Keep the rest of the function intact; on sodium.ready failure log a warning but continue (non-fatal).
  2. Increase WebSocket client handshake timeout to tolerate slightly slower handshakes (IPv6, crypto init).

    • File: src/core/networking/transport/webSocket/webSocketConnection.ts
    • Change the WEBSOCKET_HANDSHAKE_TIMEOUT constant from 2500 (2.5s) to 10000 (10s).

Why these changes:

  • Waiting for sodium.ready avoids race conditions where libp2p's crypto relies on libsodium initialisation leading to handshake delays or failures.
  • Increasing the WebSocket client handshake timeout prevents early failures of WebSocket connections in environments where handshakes take longer.

Files to modify (concise diffs / edits):

  • src/core/networking/transport/libp2p/libp2pTransport.ts

    • Add: import sodium from 'libsodium-wrappers-sumo';
    • In async start(): await sodium.ready inside a try/catch near the top.
  • src/core/networking/transport/webSocket/webSocketConnection.ts

    • Change private static WEBSOCKET_HANDSHAKE_TIMEOUT = 2500; to private static WEBSOCKET_HANDSHAKE_TIMEOUT = 10000;

Testing and validation steps (what I will do in the PR):

  • Update the two files with the changes described above.
  • Run the test suite (or at least the two failing tests) locally / CI: npm test (or the project's test script) and verify the previously failing tests pass.
  • If tests still fail, add logging around libp2p startup (listen addresses) and WebSocket handshake timing to help debug further.

Notes/assumptions:

  • I will make minimal changes and avoid changing test timeouts themselves.
  • If you'd prefer a smaller change (only sodium.ready or only ws timeout), I can open a PR with that variant instead.

Please review and confirm. If confirmed, I will create a PR that implements the two changes and run the tests in CI.

This pull request was created from Copilot chat.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

- Add await sodium.ready in libp2pTransport.start() to ensure libsodium is initialized before starting libp2p
- Increase WEBSOCKET_HANDSHAKE_TIMEOUT from 2500ms to 10000ms to tolerate slower handshakes

Co-authored-by: victorhahncastell <3177019+victorhahncastell@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix libsodium initialization timing for libp2p and WebSocket tests Fix libp2p and WebSocket IPv6 test timeouts with Node 24 and libsodium 0.8.0 Jan 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants